/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.score.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.modules.score.entity.PartyScoreDetail;
import com.fosung.frame.modules.score.service.PartyScoreDetailService;

/**
 * 党组织积分内容Controller
 * @author ygl
 * @version 2017-09-03
 */
@Controller
@RequestMapping(value = "${adminPath}/score/partyScoreDetail")
public class PartyScoreDetailController extends BaseController {

	@Autowired
	private PartyScoreDetailService partyScoreDetailService;
	
	@ModelAttribute
	public PartyScoreDetail get(@RequestParam(required=false) String id) {
		PartyScoreDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = partyScoreDetailService.get(id);
		}
		if (entity == null){
			entity = new PartyScoreDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("score:partyScoreDetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(PartyScoreDetail partyScoreDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PartyScoreDetail> page = partyScoreDetailService.findPage(new Page<PartyScoreDetail>(request, response), partyScoreDetail); 
		model.addAttribute("page", page);
		return "modules/score/partyScoreDetailList";
	}

	@RequiresPermissions("score:partyScoreDetail:view")
	@RequestMapping(value = "form")
	public String form(PartyScoreDetail partyScoreDetail, Model model) {
		model.addAttribute("partyScoreDetail", partyScoreDetail);
		return "modules/score/partyScoreDetailForm";
	}

	@RequiresPermissions("score:partyScoreDetail:edit")
	@RequestMapping(value = "save")
	public String save(PartyScoreDetail partyScoreDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, partyScoreDetail)){
			return form(partyScoreDetail, model);
		}
		partyScoreDetailService.save(partyScoreDetail);
		addMessage(redirectAttributes, "保存党组织积分内容成功");
		return "redirect:"+Global.getAdminPath()+"/score/partyScoreDetail/?repage";
	}
	
	@RequiresPermissions("score:partyScoreDetail:edit")
	@RequestMapping(value = "delete")
	public String delete(PartyScoreDetail partyScoreDetail, RedirectAttributes redirectAttributes) {
		partyScoreDetailService.delete(partyScoreDetail);
		addMessage(redirectAttributes, "删除党组织积分内容成功");
		return "redirect:"+Global.getAdminPath()+"/score/partyScoreDetail/?repage";
	}

}